{extend name="layout/iframe" /}

{block name="content"}
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="globalName" class="layui-form-label">
                <span class="x-red">*</span>商圈名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="globalName" name="globalName" value="{$data.globalName}" lay-verify="globalName" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="col-md-6">
                <div class="row selectCon">
                    <div class="layui-form-item" id="x-city">
                        <label class="layui-form-label">商圈地址</label>
                        <div class="layui-input-inline">
                            <select name="province" id="province" class="areaLists" lay-filter="province">
                                <option value="">请选择省</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="city" id="city" class="areaLists" lay-filter="city">
                                <option value="">请选择市</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="area" id="district" class="areaLists" lay-filter="area">
                                <option value="">请选择县/区</option>
                            </select>
                        </div>
                    </div>
                </div>
                <br />
                <div class="add-more " style="margin-top: 0">
                    <div class="layui-input-inline" style="width:600px;margin-left: 10%;">
                        <input type="text" id="address" name="input_address" lay-verify="input_address" autocomplete="off" class="layui-input" value="{$data.addressName}">
                        <input id="addtxt" type="hidden" />
                        <input type="hidden" id="add-text1" value="" class="form-control input-large" style="position: relative;top: 300px;left: 0px;z-index: 1;" name="addressGeo">
                        <div style="width:100%;height:300px;" id="map_container"></div>
                    </div>
                </div>
                <input type="hidden" name="buissId" value="{$data.id}">
                <input class="addprovince" type="hidden" value="{$data.province}"></input>
                <input class="addcity" type="hidden" value="{$data.city}"></input>
                <input class="adddistrict" type="hidden" value="{$data.district}"></input>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </form>
</div>

<script type="text/javascript" src="__STATIC__/admin/js/xcity.js?v={:time()}"></script>
<script src="https://api.map.baidu.com/api?v=2.0&ak=07E2669c3b77a0793274952ba61cd8b8&s=1" type="text/javascript"></script>
<script type="text/javascript" src="__STATIC__/admin/js/baidumap.js?v={:time()}"></script>
<script>
    var provincetxt = $(".addprovince").val();
    var citytxt = $(".addcity").val();
    var districttxt = $(".adddistrict").val();
    console.log(provincetxt + citytxt + districttxt);
    //省市区赋值
    if(provincetxt != "" && citytxt != "" && districttxt != "") {
        $("#addtxt").val(provincetxt + ',' + citytxt + ',' + districttxt);
    }
    layui.use(['form','code'], function(){
        form = layui.form;
        layui.code();
        $('#x-city').xcity(provincetxt,citytxt,districttxt);
    });

    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            globalName: function(value){
                if(value == ''){
                    return '商圈名称不能为空';
                }
            }
            ,input_address: function(value){
                if(value == ''){
                    return '地址不能为空';
                }
            }
            ,addressGeo:function (value) {
                if(value == ''){
                    return '没有获取到经纬度';
                }
            }
//            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
//            ,repass: function(value){
//                if($('#L_pass').val()!=$('#L_repass').val()){
//                    return '两次密码不一致';
//                }
//            }
        });

        //监听提交
        form.on('submit(add)', function(data){
            console.log(data.field);
            //发异步，把数据提交给php
            $.ajax({
                url:"{:url('Businessarea/addoreditpost')}",
                data:data.field,
                type:"POST",
                dataType:"json",
                success:function(data){
                    if(data.status == 1){
                        layer.msg(data.message);
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    }else {
                        layer.msg(data.message);
                    }

                },
                error:function(data){
                    layer.msg("服务器无响应");
                }
            });

            return false;
        });
    });
</script>
{/block}